package com.example.dormitorysystem.mapper;

import com.example.dormitorysystem.entity.Beds;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 吉吉王国组
 * @since 2022-11-26
 */
public interface BedsMapper extends BaseMapper<Beds> {


    @Select("select * from beds where uid = #{uid}")
    Beds selectByUid(@Param("uid") Integer uid);

    @Select("select name from users where uid in (select uid from beds where room_id = #{roomId})")
    List<String> selectListByRoomId(@Param("roomId") Integer room_id);

    @Select("select * from beds where room_id = #{room_id} and is_valid = 1 and is_del = 0 and status = 0")
    List<Beds> getBedCountsByRoomId(@Param("room_id") Integer room_id);

    @Select("select * from beds where room_id = #{room_id} and is_valid = 1 and is_del = 0 and status = 0 limit 1")
    Beds selectOneBedByRoomId(Integer id);
}
